package com.riant.day08;

/**
 * @Classname Demo03
 * @Description TODO
 * @Date 2021/3/24 10:18
 * @Created by 张斌
 */
public class Demo03 implements Runnable {

    private static String winner;

    @Override
    public void run() {
        for (int i = 0; i <= 100; i++) {
            boolean flag = gameOver(i);
            if (flag) {
                break;
            }
            System.out.println(Thread.currentThread().getName() + "-->跑了" + i + "步");
        }
    }

    private boolean gameOver(int steps) {
        if (winner != null) {
            return true;
        } else if (steps >= 100) {
            winner = Thread.currentThread().getName();
            System.out.println("winner is" + winner);
            return true;
        } else {
            return false;
        }
    }

    public static void main(String[] args) {
        Demo03 demo03=new Demo03();
        new Thread(demo03,"兔子").start();
        new Thread(demo03,"乌龟").start();
    }
}
